<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../layui.css">
</head>
<body>        
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
</fieldset>
<form class="layui-form" action="/admin/material/save" method="post">
  <div class = "layui-form-item">
    <div class = "layui-inline">
    <label class="layui-form-label">课程编号</label>
    <div class="layui-input-inline">
      <input type="text" name="courseSerial" required lay-verity = "required" placeholder="请输入课程编码" autocomplete="off" class="layui-input courseSerial">
    </div>
    </div>
    <div class = "layui-inline">
      <label class="layui-form-label">申报人</label>
      <div class = "layui-input-inline">
        <input type="text" name="tName" required lay-verity = "required" placeholder="请输入申报人" autocomplete="off" class = "layui-input tName">
      </div>
    </div>
  </div>
  <div class = "layui-form-item">
    <div class = "layui-inline">
    <label class="layui-form-label">教材名称</label>
    <div class="layui-input-inline">
      <input type="text" name="name" required  lay-verify="required" placeholder="请输入教材名称" autocomplete="off" class="layui-input name" >
    </div>
    </div>
    <div class = "layui-inline">
      <label class="layui-form-label">ISBN</label>
      <div class = "layui-input-inline">
        <input type="text" name="isbn" required lay-verity = "required" placeholder="请输入ISBN" autocomplete="off" class = "layui-input isbn">
      </div>
    </div>
  </div>
  <div class = "layui-form-item">
    <div class = "layui-inline">
      <label class = "layui-form-label">出版社</label>
      <div class= "layui-input-inline">
        <input type="text" name="press" required lay-verity = "required" placeholder="请输入出版社" autocomplete="off" class ="layui-input press">
      </div>
    </div>
    <div class = "layui-inline">
      <label class="layui-form-label">作者</label>
      <div class = "layui-input-inline">
        <input type="text" name="author" required lay-verity = "required" placeholder="请输入作者" autocomplete="off" class = "layui-input author">
      </div>
    </div>
  </div>
  <div class = "layui-form-item">
    <div class = "layui-inline">
      <label class = "layui-form-label">出版号</label>
      <div class= "layui-input-inline">
        <input type="text" name="versionNum" required lay-verity = "required" placeholder="请输入出版号" autocomplete="off" class ="layui-input versionNum">
      </div>
    </div>
    <div class = "layui-inline">
      <label class="layui-form-label">出版时间</label>
      <div class = "layui-input-inline">
        <input type="text" name="versionDate" id="date" required lay-verity = "date" placeholder="请选择出版时间" autocomplete="off" class = "layui-input versionDate">
      </div>
    </div>
  </div>
  <div class="layui-form-item">
    <div class = "layui-inline">
      <label class="layui-form-label">国家级优秀教材</label>
      <div class="layui-input-block">
          <input type="radio" name="nationalEX" value="是" title="是" checked="">
          <input type="radio" name="nationalEX" value="否" title="否" >
      </div>
    </div>
    <div class = "layui-inline">
      <label class="layui-form-label">省级优秀教材</label>
      <div class="layui-input-block">
          <input type="radio" name="provincialEX" value="是" title="是" checked="">
          <input type="radio" name="provincialEX" value="否" title="否" >
      </div>
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">其他描述</label>
    <div class="layui-input-block">
      <textarea name="script" placeholder="请输入内容" class="layui-textarea script" ></textarea>
    </div>
  </div>
  <div class="layui-form-item">

    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
<!--   <div class="layui-form-item">
    <label class="layui-form-label">密码框</label>
    <div class="layui-input-inline">
      <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">辅助文字</div>
  </div> -->
<!--   <div class="layui-form-item">
    <label class="layui-form-label">选择框</label>
    <div class="layui-input-block">
      <select name="city" lay-verify="required">
        <option value=""></option>
        <option value="0">北京</option>
        <option value="1">上海</option>
        <option value="2">广州</option>
        <option value="3">深圳</option>
        <option value="4">杭州</option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">复选框</label>
    <div class="layui-input-block">
      <input type="checkbox" name="like[write]" title="写作">
      <input type="checkbox" name="like[read]" title="阅读" checked>
      <input type="checkbox" name="like[dai]" title="发呆">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">开关</label>
    <div class="layui-input-block">
      <input type="checkbox" name="switch" lay-skin="switch">
    </div>
  </div> -->

</form>

<script src="../layui.js" charset="utf-8"></script>

<script src="../jquery.min.js"></script>
<script>
function getQueryVariable(variable){
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
    }
    return(false);
}
function setMessage(){
  var a = getQueryVariable("id");
  $.ajax({
    url:"/admin/course/getById/"+a,
    type:"post",
    dataType:"json",
    data:{},
    success:function(result){
      var message = result.data;
      console.log(message.tname);
      $(".tName").val(message.tname);
      $(".courseSerial").val(message.courseSerial);
    },
    error:function(result){
      console.log("setMessage()出错了");
    }
  })
} 


layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  
  setMessage();
  //日期
  laydate.render({
    elem: '#date'
  });
  //创建一个编辑器
  var editIndex = layedit.build('LAY_demo_editor');
 
  //自定义验证规则

  //以后要留下的验证区域



  form.verify({
    title: function(value){
      if(value.length < 5){
        return '标题至少得5个字符啊';
      }
    }
    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });






  
  
/*  //监听指定开关
  form.on('switch(switchTest)', function(data){
    layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
      offset: '6px'
    });
    layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
  });*/
  
  //监听提交
  
  form.on('submit(formDemo)', function(data){
    console.log(data.field);

    var jhxhr = $.ajax({
      'url': data.form.action,
      'data': data.field,
      'type': 'POST'
    });
    
    jhxhr.done(function(result) {
     alert("添加成功");  
    });

   /*  layer.alert(JSON.stringify(data.field), {
      title: '最终的提交信息'
    }) */
    return false;
  });


});

</script>

</body>
</html>